﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>潜在客户管理</title>
<#--引入的一些核心文件-->
    <#include "../common/link.ftl">
    <script>
        $(function () {
            //新增/编辑
            $('.btn-input').click(function () {
                //如果json不存在,不需要显示,要把表单里之前回显的内容清空
                $('#editForm select').val('-1');
                $('#editForm input').val('');
                var json = $(this).data("json");
                //获取编辑里定义的json
                //如果存在就是编辑,需要回显
                if (json) {
                    $('input[name=id]').val(json.id);
                    $('input[name=name]').val(json.name);
                    $('input[name=age]').val(json.age);
                    $('select[name=gender]').val(json.gender);
                    $('input[name=tel]').val(json.tel);
                    $('input[name=qq]').val(json.qq);
                    $("select[name='job.id']").val(json.job.id);
                    $("select[name='source.id']").val(json.source.id);
                }
                $('#myModal').modal('show');
            })

            //异步请求保存
            /* $('.btn-submit').click(function () {
                 $('#editForm').ajaxSubmit(handleMessage)
             })*/

            $('#editForm').bootstrapValidator({
                feedbackIcons: {
                    valid: 'glyphicon glyphicon-ok',
                    invalid: 'glyphicon glyphicon-remove',
                    validating: 'glyphicon glyphicon-refresh'
                },
                fields: {
                    tel: {
                        validators: {
                            notEmpty: {
                                message: '手机号不能为空'
                            },
                            remote: {
                                type: 'POST',
                                url: '/customer/checkTel.do',
                                data: {
                                    id: $('#cId').val()
                                },
                                message: '此手机号已经存在',
                                delay: 1000
                            }
                        }
                    }
                }
            }).on('success.form.bv', function (e) { //表单所有数据验证通过后执行里面的代码
                //禁止原本的表单提交
                e.preventDefault();
                $("#editForm").ajaxSubmit(function (data) {
                    if (data.success) { //用alert或者popup都可以
                        $.messager.alert("温馨提示", "保存成功!1s后自动关闭")
                        window.setTimeout(function () {
                            window.location.href = "/customer/potentialList.do";
                        }, 1000)
                    } else {
                        $.messager.popup(data.msg)
                    }
                })
            });


            //跟进相关功能============================================================
            //跟进历史模态框展示
            $('.btn-trace').click(function () {
                var json = $(this).data("json");
                //回显当前客户的名字
                $('#traceForm input[name=name]').val(json.name);
                $('#traceForm input[name="customer.id"]').val(json.id);
                $('#traceModal').modal('show');
            })
            //提交跟进历史的模态框
            $('.traceSubmit').click(function () {
                $('#traceForm').ajaxSubmit(handleMessage);
            })

            //跟进时间插件的配置
            $("input[name=traceTime]").datepicker({
                language: "zh-CN",
                autoclose: true,
                todayHighlight: true
            });

            //移交相关功能============================================================
            $('.btn-transfer').click(function () {
                var json = $(this).data("json");
                $("#transferForm input[name='customer.id']").val(json.id);
                $("#transferForm input[name='customer.name']").val(json.name);
                $("#transferForm input[name='oldseller.id']").val(json.sellerId);
                $("#transferForm input[name='oldseller.name']").val(json.sellerName);
                $('#transferModal').modal('show');
            })
            //提交移交历史的模态框
            $('.transferSubmit').click(function () {
                $('#transferForm').ajaxSubmit(handleMessage);
            })
        })
    </script>
</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
    <#include "../common/navbar.ftl">
    <#assign currentMenu="customer_potential">
    <#include "../common/menu.ftl">
    <div class="content-wrapper">
        <section class="content-header">
            <h1>潜在客户管理</h1>
        </section>
        <section class="content">
            <div class="box">
                <form class="form-inline" id="searchForm" action="/customer/potentialList.do" method="post">
                    <input type="hidden" name="currentPage" id="currentPage" value="1">
                    <a href="#" class="btn btn-success btn-input" style="margin: 10px">
                        <span class="glyphicon glyphicon-plus"></span> 添加
                    </a>
                    <div class="form-group">
                        <label for="keyword">关键字:</label>
                        <input type="text" class="form-control" id="keyword" name="keyword" value="${qo.keyword!}"
                               placeholder="请输入姓名/电话">
                    </div>
                <#--通过销售人员查询下拉框-->
                <#--销售人员下拉框,是提供给管理员或者经理用的, 不应该给普通销售员看到-->
                    <@shiro.hasAnyRoles name="admin,Market_Manager">
                    <div class="form-group">
                        <label for="sellerId"> 销售员:</label>
                        <select class="form-control" id="sellerId" name="sellerId">
                            <option value="-1">全部</option>
                                <#list employees as e>
                                    <option value="${e.id}">${(e.name)!}</option>
                                </#list>
                        </select>
                    <#--查询时回显选中的销售员-->
                        <script>
                            $('#sellerId').val(${qo.sellerId});
                        </script>
                    </div>
                    </@shiro.hasAnyRoles>
                <#--按钮在表单内,不写type,默认是submit,可以提交,若是button没法提交-->
                    <button id="btn_query" class="btn btn-primary"><span class="glyphicon glyphicon-search"></span> 查询
                    </button>
                </form>
                <!--编写内容-->
                <div class="box-body table-responsive no-padding ">
                    <table class="table table-hover table-bordered">
                        <tr>
                            <th>编号</th>
                            <th>姓名</th>
                            <th>电话</th>
                            <th>QQ</th>
                            <th>职业</th>
                            <th>来源</th>
                            <th>销售员</th>
                            <th>状态</th>
                            <th>操作</th>
                        </tr>
                        <#list result.list as customer>
                            <tr>
                            <#--取值后面加个感叹号可以解决空指针问题,也可以感叹后加个默认值-->
                                <td>${customer_index+1}</td>
                                <td>${customer.name!}</td>
                                <td>${customer.tel!}</td>
                                <td>${customer.qq!}</td>
                                <td>${(customer.job.title)!}</td>
                                <td>${(customer.source.title)!}</td>
                                <td>${(customer.seller.name)!}</td>
                                <td>${customer.statusName!}</td>
                                <td>
                                <#--data-json后面要用单引号,不然json字符串过来拼接会有问题-->
                                <#--编辑的时候需要将update的sql中不用修改的参数删掉,不然全部默认为空-->
                                    <a href="#" class="btn btn-info btn-xs btn-input" data-json='${customer.json!}'>
                                        <span class="glyphicon glyphicon-pencil"></span> 编辑
                                    </a>
                                    <a href="#" class="btn btn-info btn-xs btn-trace" data-json='${customer.json!}'>
                                        <span class="glyphicon glyphicon-pencil"></span> 跟进
                                    </a>
                                    <#--如果不是高层,不能看到移交按钮-->
                                    <@shiro.hasAnyRoles name="admin,Market_Manager">
                                    <a href="#" class="btn btn-danger btn-xs btn-transfer" data-json='${customer.json!}'>
                                        <span class="glyphicon glyphicon-pencil"></span> 移交
                                    </a>
                                     </@shiro.hasAnyRoles>
                                </td>
                            </tr>
                        </#list>
                    </table>
                    <!--分页-->
                    <#include "../common/page.ftl">
                </div>
            </div>
        </section>
    </div>
<#--引入主页面的底部(一些公司的信息)-->
    <#include "../common/footer.ftl">
</div>

<#--客户编辑模态框-->
<div class="modal fade" id="myModal">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title inputTitle">客户编辑</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/customer/saveOrUpdate.do" method="post" id="editForm">
                    <input type="hidden" id="cId" name="id">
                    <div class="form-group">
                        <label class="col-sm-3 control-label">客户名称：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="name"
                                   placeholder="请输入客户姓名"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">客户年龄：</label>
                        <div class="col-sm-6">
                            <input type="number" class="form-control" name="age"
                                   placeholder="请输入客户年龄"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">客户性别：</label>
                        <div class="col-sm-6">
                            <select class="form-control" name="gender">
                                <option value="1">男</option>
                                <option value="0">女</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">客户电话：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="tel"
                                   placeholder="请输入客户电话"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">客户QQ：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="qq"
                                   placeholder="请输入客户QQ"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">客户工作：</label>
                        <div class="col-sm-6">
                            <select class="form-control" name="job.id">
                                <option value="-1">全部</option>
                                <#list jobs as j>
                                    <option value="${j.id}">${j.title}</option>
                                </#list>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">客户来源：</label>
                        <div class="col-sm-6">
                            <select class="form-control" name="source.id">
                                <option value="-1">全部</option>
                                <#list sources as s>
                                    <option value="${s.id}">${s.title}</option>
                                </#list>
                            </select>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="submit" class="btn btn-primary btn-submit">保存</button>
                        <button type="submit" class="btn btn-default" data-dismiss="modal">取消</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<#--跟进历史-->
<div class="modal fade" id="traceModal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">跟进</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/customerTraceHistory/saveOrUpdate.do" method="post"
                      id="traceForm">
                <#--新增跟进历史没有ID,客户应该要有ID,不然就不知道当前是哪个客户的跟进历史-->
                    <input type="hidden" name="customer.id"/>
                <#--当前页面是潜在页面,所以在这里给type直接设置一个0提交-->
                    <input type="hidden" name="type" value="0">
                    <div class="form-group">
                        <label class="col-lg-4 control-label">客户姓名：</label>
                        <div class="col-lg-6">
                            <input type="text" class="form-control" readonly name="name"/>
                            <input type="hidden" name="customer.id">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">跟进时间：</label>
                        <div class="col-lg-6 ">
                            <input type="text" class="form-control " name="traceTime" placeholder="请输入跟进时间">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">跟进记录：</label>
                        <div class="col-lg-6">
                            <input type="text" class="form-control" name="traceDetails"
                                   placeholder="请输入跟进记录"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">交流方式：</label>
                        <div class="col-lg-6">
                            <select class="form-control" name="traceType.id">
                                <#list ccts as c>
                                    <option value="${c.id}">${c.title}</option>
                                </#list>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">跟进结果：</label>
                        <div class="col-lg-6">
                            <select class="form-control" name="traceResult">
                                <option value="3">优</option>
                                <option value="2">中</option>
                                <option value="1">差</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">备注：</label>
                        <div class="col-lg-6">
                            <textarea type="text" class="form-control" name="remark"></textarea>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary traceSubmit">保存</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>
</div>

<#--移交模态框-->
<div id="transferModal" class="modal fade" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title">新增/编辑</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/customerTransfer/saveOrUpdate.do" method="post" id="transferForm"
                      style="margin: -3px 118px">
                    <input type="hidden" name="id" id="customerTransferId"/>
                    <div class="form-group">
                        <label for="name" class="col-sm-4 control-label">客户姓名：</label>
                        <div class="col-sm-8">
                            <input type="text" class="form-control" name="customer.name" readonly>
                            <input type="hidden" class="form-control" name="customer.id">
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="sn" class="col-sm-4 control-label">旧营销人员：</label>
                        <div class="col-sm-8">
                            <input type="text" class="form-control" name="oldseller.name" readonly>
                            <input type="hidden" class="form-control" name="oldseller.id">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="sn" class="col-sm-4 control-label">新营销人员：</label>
                        <div class="col-sm-8">
                            <select name="newseller.id" id="newseller" class="form-control">
                                <#list employees as e>
                                    <option value="${e.id}">${e.name}</option>
                                </#list>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="sn" class="col-sm-4 control-label">移交原因：</label>
                        <div class="col-sm-8">
                            <textarea type="text" class="form-control" id="reason" name="reason" cols="10"></textarea>
                        </div>
                    </div>

                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary transferSubmit">保存</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
</body>
</html>
